package com.zw.yzk.kabu.data.repository;

import android.content.Context;

import com.zw.yzk.kabu.data.network.ServiceGenerator;
import com.zw.yzk.kabu.data.network.entity.SplashEntity;
import com.zw.yzk.kabu.data.network.service.SplashService;
import com.zw.yzk.kabu.data.network.task.Task;
import com.zw.yzk.kabu.data.utils.SharedPrefrenceUtils;

import javax.inject.Inject;

import rx.Observable;
import rx.functions.Func1;

/**
 * Created by zhanwei on 2016/12/24.
 */

public class SplashImageRepository extends CommonRepository {

    private Context context;
    @Inject
    public SplashImageRepository(Context context) {
        this.context = context;
    }

    @Override
    protected Observable connectServer(Task task) {
        SplashService service = ServiceGenerator.createService(SplashService.class);
        return service.getSplashImage();
    }

    @Override
    protected Func1<SplashEntity, Observable> getServerData() {
        return new Func1<SplashEntity, Observable>() {
            @Override
            public Observable call(SplashEntity splashEntity) {
                SharedPrefrenceUtils.setValue(context, SharedPrefrenceUtils.getSplashImageKey(), splashEntity.result.image);
                return Observable.just(splashEntity);
            }
        };
    }

}
